package logic

import (
	"context"
	"doc/doc_srv/internal/svc"
	"doc/doc_srv/pb"
	"doc/model/mysql"
	"github.com/zeromicro/go-zero/core/logx"
)

type DocListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDocListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocListLogic {
	return &DocListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// ToDo:医生查询

func (l *DocListLogic) DocList(in *pb.DocListReq) (*pb.DocListResp, error) {
	// todo: add your logic here and delete this line
	doc := mysql.Doc{
		Name: in.Name,
	}
	list, err := doc.DocList()
	if err != nil {
		logx.Error("查询信息无效")
		return nil, err
	}
	var docInfo []*pb.DocInfo
	for _, v := range list {
		docInfo = append(docInfo, &pb.DocInfo{
			DocId: int64(v.ID),
			Name:  v.Name,
		})
	}
	return &pb.DocListResp{DocInfo: docInfo}, nil
}
